package com.ygxsk.carhome.ui.care;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.StringUtils;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.jakewharton.rxbinding4.widget.RxTextView;
import com.jakewharton.rxbinding4.widget.TextViewAfterTextChangeEvent;
import com.kongzue.dialogx.dialogs.PopTip;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.alertview.OnItemClickListener;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.enumwrap.CardAuditStatus;
import com.ygxsk.carhome.enumwrap.CardCareTypes;
import com.ygxsk.carhome.event.EventCardMain;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.listener.GainDataCallBackListener;
import com.ygxsk.carhome.listener.RxBus;
import com.ygxsk.carhome.response.CouponCustomer;
import com.ygxsk.carhome.response.CustomerPerson;
import com.ygxsk.carhome.response.EvaluateWadeInfo;
import com.ygxsk.carhome.response.GreatPackageCustomerVo;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.rxbus.RxBusCarWade;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.evaluate.EvaluateWadePopu;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.views.ClearEditText;
import com.ygxsk.carhome.views.FJEditTextCountPublishTooSmallLight;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-25  12:03
 * @Description:卡券发放的主要列表,2023年10月7日11:34:21 以前是仅仅只有优惠券的列表，后边又新增了 优惠大礼包的需求；
 *
 */
public class CardMainPushActivity extends ErrorActivity {

    //单选按钮的内容
    @BindView(R.id.radioGroupCheckCareCardTypepush)
    RadioGroup radioGroupCheckCareCardType;

    //发放普通的优惠券
    @BindView(R.id.radiaoButtonChooseTypeCouponspush)
    RadioButton radiaoButtonChooseTypeCoupons;

    //发放优惠券大礼包
    @BindView(R.id.radiaoButtonChooseTypeGreatPackagepush)
    RadioButton radiaoButtonChooseTypeGreatPackage;

    //卡券类型的默认描述 左侧：卡券类型
    @BindView(R.id.textviewcardtypedespush)
    TextView textViewCardTypeDes;

    //-------------------------------------------------

    //发送按钮
    @BindView(R.id.layoutbuttoncardplaypush)
    RoundTextView layoutButtonCardPlay;

    //卡券的类型；
    @BindView(R.id.layoutcartypepush)
    LinearLayout layoutCarType;

    //卡券的那个类型的文本填充
    @BindView(R.id.textvieweditviewcardtypenamepush)
    TextView textViewEditViewCardTypeName;

    //填充客户手机号-作为搜索条件
    @BindView(R.id.editviewinputcustomerphonesearchpush)
    ClearEditText editViewInputCustomerPhoneSearch;

    //添加【搜索】的按钮
    @BindView(R.id.textviewsmartsearchpush)
    RoundTextView textViewSmartSearch;

    //添加发放优惠券的原因文本框
    @BindView(R.id.editviewcontentreasoncou)
    FJEditTextCountPublishTooSmallLight editViewContentReasonCou;

//    @BindView(R.id.determinate_circular_progress)
//    MaterialProgressBar determinate_circular_progress;

//    @BindView(R.id.determinate_circular_small_progress)
//    MaterialProgressBar determinate_circular_small_progress;

    @BindView(R.id.textviewcardforbidden)
    TextView textViewCardForbidden;

    //优惠券类型或者优惠券礼包类型
    private BasePopupView basePopupViewCardTypeOrgreatPackage;

    //弹出是 搜索出来的这个客户的 列表
    private BasePopupView basePopupView_customerPerson;
    private BasePopupView basePopupView_cardTwoListPopu;
    //卡券类型 列表适配器；是多个动态的展示；
    private ArrayList<CouponCustomer> mDataResources_couponCustomer = new ArrayList<>();
    //礼包的类型 列表适配器 多个动态的展示
    private ArrayList<GreatPackageCustomerVo> mDataResources_greatPackageCustomer = new ArrayList<>();


    //优惠券类型，优惠券礼包类型：列表适配器的弹窗展示用到
    private ArrayList<EvaluateWadeInfo> mDataResources_cardTypeOrPackageType_popu = new ArrayList<>();
    //该页面的优惠券发放的历史记录
//    private ArrayList<CouponCustomerVo> mDataResources = new ArrayList<>();


    //外侧 用于遍历 搜索客户人员外侧列表，
    private ArrayList<CustomerPerson> mDataResources_customerPerson_outSide = new ArrayList<>();
    //这里的弹窗是 客户的信息,
    private ArrayList<EvaluateWadeInfo> mDataResources_customerPerson_for_popu = new ArrayList<>();


    //添加
//    private CardMainBottomAdapter cardMainBottomAdapter;
    /**
     * 最后一条上传的id的信息内容
     */
//    private int pagination_upLoad = Parameterkey.pageNum_default_first;

    //选择的这个客户的id ,用在发送 优惠券上；
    private String customerId_upLoad;


    //选中的这个优惠券的id,用在 发送 发放 优惠券上；
    private String couponId_upLoad;
    //选中的礼包类型，做上传用；
    private String couponPackId_upLoad;


    //搜索客户的时候-是否 需要用车牌号搜索；0是不需要车牌号，1是需要车牌号：
    private int isCarNo_upLoad;
    //真实的车牌号信息 上传；
    private String carNo_upLoad;

    //默认是选中类型是【优惠券】
    private int care_cardOrPackage_type = CardCareTypes.TYPE_COUPONS.getIndex();

    //跳转到历史记录页面
    private void method_go_history(boolean extra_ischecked_more_items_flag, String couponPackId_upLoad) {

        Bundle extra_bundle = new Bundle();
        //携带是从哪个页面过去的？
        //携带标志 是从 客户关怀过去的
        extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_ACTIVITY);

        //是否是批量审核跳转携带值内容
        extra_bundle.putBoolean(ExtraKey.EXTRA_ISCHECKED_MORE_ITEMS_FLAG, extra_ischecked_more_items_flag);

        //携带优惠券本身属于哪一个优惠券大礼包下的 优惠券大礼包id: EXTRA_COUPONPACKID_UPLOAD
        extra_bundle.putString(ExtraKey.EXTRA_COUPONPACKID_UPLOAD, couponPackId_upLoad);

        ActivityUtils.startActivity(extra_bundle, CardSumHistoryActivity.class);

    }

    @OnClick({R.id.layoutcartypepush,//选择卡券类型
            R.id.layoutbuttoncardplaypush,//去派发卡券或者礼包
            R.id.textviewsmartsearchpush//搜索逻辑
    })
    public void ClickInCardMain(View view) {

        KeyboardUtils.hideSoftInput(CardMainPushActivity.this);

        switch (view.getId()) {

//            case R.id.constraintlayoutheadersmartgo: {//跳转历史记录，不是批量审核筛选标志
//
//                //2024-1-2 不是批量审核，那么传递0，过去之后再以零做判断
//                method_go_history(false, ConstantSign.NUMBER_ZERO);
//
//                break;
//            }

            case R.id.layoutcartypepush: {//选择卡券类型；或者 选中的是 优惠礼包 类型

//                CardTypeInfoBean cardTypeInfoBean = new CardTypeInfoBean();
//                cardTypeInfoBean.setCardName("奔驰卡券");
//                cardTypeInfoBean.setCardType("1");
//                CardTypeInfoBean cardTypeInfoBean1 = new CardTypeInfoBean();
//                cardTypeInfoBean1.setCardName("大众卡券");
//                cardTypeInfoBean1.setCardType("2");
                // 数据库之中存入
//                CardTypeInfoDaoManager.getInstance().insertMultCardTypeStation(cardTypeInfoListForCardMain);
//                nice_spinner_customer_info.setText(StringUtils.getString(R.string.pleseselectcardtype));

                //切换是选中【卡券类型】还是【优惠礼包】类型；
                if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中的是优惠券类型");

                    if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {

                        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardMainPushActivity.this,//
                                ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_CARD_TYPE,//
                                mDataResources_cardTypeOrPackageType_popu);

                        evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_card_form));

                        //直接弹窗：
                        basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardMainPushActivity.this)
                                .hasShadowBg(true)
                                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面.
                                .isViewMode(true)
                                //.autoDismiss(false)
                                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                //.dismissOnTouchOutside(true)
                                //.notDismissWhenTouchInView()
                                .moveUpToKeyboard(false)
                                .asCustom(evaluateWadePopu)//
                                .show();

                    } else {

                        //直接获取接口数据
                        getServerDatasCouponType(new GainDataCallBackListener() {
                            @Override
                            public void doSomeThing() {

                                EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardMainPushActivity.this,//
                                        ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_CARD_TYPE,//
                                        mDataResources_cardTypeOrPackageType_popu);

                                evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_card_form));

                                //直接弹窗：
                                basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardMainPushActivity.this)
                                        .hasShadowBg(true)
                                        //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                                        .isViewMode(true)
                                        //.autoDismiss(false)
                                        //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                        //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                        //.dismissOnTouchOutside(true)
                                        //.notDismissWhenTouchInView()
                                        //.moveUpToKeyboard(false)
                                        .asCustom(evaluateWadePopu)//
                                        .show();

                            }
                        });
                    }

                } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中的是优惠券  礼包 类型");

                    if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {

                        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardMainPushActivity.this,//
                                ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_GREAT_PACKAGE_TYPE,//
                                mDataResources_cardTypeOrPackageType_popu);

                        evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_great_package_form));

                        //直接弹窗：
                        basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardMainPushActivity.this)
                                .hasShadowBg(true)
                                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面.
                                .isViewMode(true)
                                //.autoDismiss(false)
                                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                //.dismissOnTouchOutside(true)
                                //.notDismissWhenTouchInView()
                                .moveUpToKeyboard(false)
                                .asCustom(evaluateWadePopu)//
                                .show();

                    } else {

                        //直接获取礼包的列表接口
                        getServerDatasGreatPackageType(new GainDataCallBackListener() {
                            @Override
                            public void doSomeThing() {

                                EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardMainPushActivity.this,//
                                        ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_GREAT_PACKAGE_TYPE,//
                                        mDataResources_cardTypeOrPackageType_popu);

                                evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_great_package_form));

                                //直接弹窗：
                                basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardMainPushActivity.this)
                                        .hasShadowBg(true)
                                        //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                                        .isViewMode(true)
                                        //.autoDismiss(false)
                                        //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                        //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                        //.dismissOnTouchOutside(true)
                                        //.notDismissWhenTouchInView()
                                        //.moveUpToKeyboard(false)
                                        .asCustom(evaluateWadePopu)//
                                        .show();

                            }
                        });
                    }

                }

                break;
            }

            case R.id.textviewsmartsearchpush: {//开始【搜索】客户；

                //搜索 客户 之前 一定要先执行【选择卡券类型】；但是2024年1月15日14:59:14要求去掉这个拦截。

//                if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {
//                    //如果选中的是优惠券，那么校验优惠券的内容；
//
//                    //校验优惠券类型 的选中
//                    if (TextUtils.isEmpty(couponId_upLoad)) {
//                        CommUtils.checkDialog(mAlertView);
//                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_coupon_upload), true);
//                        mAlertView.show();
//                        return;
//                    }
//
//
//                } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {
//
//                    //校验 礼包类型的 选中
//                    if (TextUtils.isEmpty(couponPackId_upLoad)) {
//                        CommUtils.checkDialog(mAlertView);
//                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_great_package_upload), true);
//                        mAlertView.show();
//                        return;
//                    }
//
//                }

                method_SearchSomeThing(true);

                break;
            }

            case R.id.layoutbuttoncardplaypush: {//卡券的发送和提交

                if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {
                    //如果选中的是优惠券，那么校验优惠券的内容；

                    //校验优惠券的选中
                    if (TextUtils.isEmpty(couponId_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_coupon_upload), true);
                        mAlertView.show();
                        return;
                    }

                } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

                    //如果选中的是 优惠礼包，那么就校验 礼包的选中情况
                    if (TextUtils.isEmpty(couponPackId_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_great_package_upload), true);
                        mAlertView.show();
                        return;
                    }

                }

                //校验用户的选中
                if (TextUtils.isEmpty(customerId_upLoad)) {
                    CommUtils.checkDialog(mAlertView);
                    mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_person_upload), true);
                    mAlertView.show();
                    return;
                }

                CommUtils.checkDialog(mAlertView);
                mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //提示
                        StringUtils.getString(R.string.alert_message_card_coupon),//提示内容:确定发送吗？
                        StringUtils.getString(R.string.clearcachecancel), //取消
                        new String[]{StringUtils.getString(R.string.clearaddorsubmitsure)},//确定
                        null, mActivityInstance, AlertView.Style.Alert, new OnItemClickListener() {//
                    @Override
                    public void onItemClick(Object o, int position) {

                        if (position != AlertView.CANCELPOSITION) {

                            if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {
                                //如果选中的是优惠券，那么发放优惠券
                                method_gainAddSubmitInfo_upLoad_for_couponCard();

                            } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {
                                //如果选中的是礼包，那么发放优惠券
                                method_gainAddSubmitInfo_upLoad_for_greatPackage();

                            }

                        }
                    }
                });

                mAlertView.setCancelable(true);
                mAlertView.show();

                //跳转到发放页面的布局；
//                Bundle extra_bundle = new Bundle();
//                    //String shopId = assetInSideBean.getShopId();
//                    //是添加进来的
//                    extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE,ExtraValue.VALUE_JUMP_FORM_ASSET_ADD);
//                    extra_bundle.putString(ExtraKey.EXTRA_ASSETINSIDEBEAN_SHOPID,assetInSideBean.getShopId());
//                    //携带服务站的列表过去
//                    extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_ASSETSTATIONINFOLISTFORADDASSET, assetStationInfoListForAddAsset);
//                    //携带资产的归属方
//                    extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_ASSETUNDERBUSINESSINFOLISTOUTSIDE, assetUnderBusinessInfoListOutSide);
//
                //这个也是车辆的分配 信息:
                // : 2023-07-15 08:43 携带不同的标志;
//                ActivityUtils.startActivity(extra_bundle, CustomerPersonActivity.class);

                break;
            }

            default:
                break;
        }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        if (mDataResources_couponCustomer == null) {
            mDataResources_couponCustomer = new ArrayList<>();
        }

        if (mDataResources_greatPackageCustomer == null) {
            mDataResources_greatPackageCustomer = new ArrayList<>();
        }

        if (mDataResources_customerPerson_outSide == null) {
            mDataResources_customerPerson_outSide = new ArrayList<>();
        }

        initloading();

        initViews();

        //这里有页面刷新，或者编辑完毕，通知页面刷新的逻辑；
//        if (!EventBus.getDefault().isRegistered(this)) {
//            EventBus.getDefault().register(this);
//        }

        gainDatas();

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected int getContentViewId() {
//        return R.layout.activity_card_main;
        return R.layout.card_main_push_activity;
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.customer_carecustom));

        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                methodBack();
            }
        });

        toolbarHelper.setLayoutClose(false, "", null);

        //右侧是【编辑】
        toolbarHelper.setLayoutRight(false, 0, "", null);

//        toolbarHelper.setLayoutRight(true, 1, getString(R.string.title_cardverifi_right), new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//                //携带信息跳转到【编辑-提交】页面；
//                Bundle extra_bundle = new Bundle();
//                //携带是 客户关怀 过去的 到卡券核销列表
//                extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_ACTIVITY);
//                ActivityUtils.startActivity(extra_bundle, CardDistHistoryActivity.class);
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

        //暂时没有

    }

    @Override
    protected void initViews() {

//        ValueAnimator mDeterminateCircularProgressAnimator =
//                Animators.makeDeterminateCircularPrimaryProgressAnimator(
//                        determinate_circular_progress);
//        mDeterminateCircularProgressAnimator.start();

        //对于选择的内容，默认是优惠券内容；
        if (radioGroupCheckCareCardType != null) {
            radioGroupCheckCareCardType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {

                    if (checkedId == R.id.radiaoButtonChooseTypeCouponspush) {//优惠券  左侧

                        method_refresh_reset();

                        //调用优惠券类型的接口:仅仅是优惠券的
                        getServerDatasCouponType(null);

                    } else if (checkedId == R.id.radiaoButtonChooseTypeGreatPackagepush) {//优惠礼包 右侧

                        care_cardOrPackage_type = CardCareTypes.TYPE_GREAT_PACKAGE.getIndex();

                        if (radiaoButtonChooseTypeCoupons != null) {
                            radiaoButtonChooseTypeCoupons.setChecked(false);
                        }

                        if (radiaoButtonChooseTypeGreatPackage != null) {
                            radiaoButtonChooseTypeGreatPackage.setChecked(true);
                        }

                        //显示礼包类型
                        if (textViewCardTypeDes != null) {
                            textViewCardTypeDes.setText(getString(R.string.choose_card_type_package));
                        }

                        //默认是礼包类型，调用礼包类型的接口
                        if (textViewEditViewCardTypeName != null) {
                            textViewEditViewCardTypeName.setText("");
                            textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_great_package_form));
                        }

                        // TODO: 2023-10-07 15:29 如果类型值被填充，要清空处理
                        //如果卡券类型或者礼包类型 有值，还是要清空的；
                        getServerDatasGreatPackageType(null);


                    }
                }
            });

        }

        //默认文字：类型 是卡券类型
        if (textViewCardTypeDes != null) {
            textViewCardTypeDes.setText(getString(R.string.choose_card_type_coupon));
        }

        //默认 选中 卡券的或者是礼包 填充的类型
        if (textViewEditViewCardTypeName != null) {
            textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_card_form));
        }

        //---------------------------------------------------------------------------------------------
        //选中用户的弹窗列表，选择优惠券的卡券类型。
        mCompositeDisposable.add(RxBus.getInstance()
                .toObserverable(RxBusCarWade.class)//
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<RxBusCarWade>() {

                    @Override
                    public void accept(RxBusCarWade rxBusCarWade) throws Throwable {

                        if (rxBusCarWade != null) {

                            if (rxBusCarWade.getActionFlag() == ExtraValue.MODIFY_EVALUATE_CARMAIN_PERSON_SELECT) {//【选择卡券发放的那个人】；

                                //搜索出这个被发放人员的
                                customerId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();

//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--customerId_upLoad-->" + customerId_upLoad);

                                //2023-9-18 11:31:57 遍历选出来的
                                if (mDataResources_customerPerson_outSide != null && !mDataResources_customerPerson_outSide.isEmpty()) {

                                    for (CustomerPerson customerPerson : mDataResources_customerPerson_outSide) {

                                        if (TextUtils.equals(customerId_upLoad, String.valueOf(customerPerson.getCustomerId()))) {

                                            carNo_upLoad = customerPerson.getCarNo();
//                                          LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--carNo_upLoad-->" + carNo_upLoad);

                                        }
                                    }
                                }

                                CommUtils.setTextTips_success(CardMainPushActivity.this, textViewCardForbidden, rxBusCarWade.getEvaluateWadeInfo().getDictLabel());

                            } else if (rxBusCarWade.getActionFlag() == ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_CARD_TYPE) {//【选择卡券类型】；

                                couponId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();
//                              LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--couponId_upLoad-->" + couponId_upLoad);

                                //2023-9-18 遍历 isCarNo 字段信息
                                if (mDataResources_couponCustomer != null && !mDataResources_couponCustomer.isEmpty()) {

                                    for (CouponCustomer couponCustomerItem : mDataResources_couponCustomer) {

                                        if (TextUtils.equals(couponId_upLoad, couponCustomerItem.getCouponId())) {

                                            isCarNo_upLoad = couponCustomerItem.getIsCarNo();
                                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "-选择卡券的类型是否需要车牌-isCarNo_upLoad-->" + isCarNo_upLoad);

                                        }

                                    }

                                }

                                if (textViewEditViewCardTypeName != null) {
                                    textViewEditViewCardTypeName.setText(rxBusCarWade.getEvaluateWadeInfo().getDictLabel());
                                }

                            } else if (rxBusCarWade.getActionFlag() == ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_GREAT_PACKAGE_TYPE) {//【选择大礼包类型】

                                couponPackId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--couponId_upLoad-->" + couponId_upLoad);

                                //2023-9-18 遍历 isCarNo 字段信息
                                if (mDataResources_greatPackageCustomer != null && !mDataResources_greatPackageCustomer.isEmpty()) {

                                    for (GreatPackageCustomerVo greatPackageCustomerVoItem : mDataResources_greatPackageCustomer) {

                                        if (TextUtils.equals(couponPackId_upLoad, greatPackageCustomerVoItem.getCouponPackId())) {

                                            isCarNo_upLoad = greatPackageCustomerVoItem.getIsCarNo();
                                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--大礼包的类型选中--isCarNo_upLoad-->" + isCarNo_upLoad);

                                        }

                                    }
                                }

                                if (textViewEditViewCardTypeName != null) {
                                    textViewEditViewCardTypeName.setText(rxBusCarWade.getEvaluateWadeInfo().getDictLabel());
                                }

                            }
                        }
                    }
                }));

        //软键盘的【搜索】
        if (editViewInputCustomerPhoneSearch != null) {
            editViewInputCustomerPhoneSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {

                    if (actionId == EditorInfo.IME_ACTION_SEARCH || (keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {

                        //关闭软键盘
                        if (KeyboardUtils.isSoftInputVisible(CardMainPushActivity.this)) {
                            KeyboardUtils.hideSoftInput(CardMainPushActivity.this);
                        }

                        method_SearchSomeThing(false);

                        return true;
                    }

                    return false;
                }
            });
        }

        //监听手机号的文本框：如果手机号文本框输入信息丢失，那么 textViewInputPhoneChoose 的文字 也改为原始文字：
        RxTextView.afterTextChangeEvents(editViewInputCustomerPhoneSearch)
//                .debounce(ConstantApi.TIME_DELAY100, TimeUnit.MILLISECONDS)//立即执行搜索
                .debounce(0, TimeUnit.MILLISECONDS)//立即执行搜索
                .skip(1)//过滤到第一个空字符的内容,需要完整的手机号
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<TextViewAfterTextChangeEvent>() {
                    @Override
                    public void accept(TextViewAfterTextChangeEvent textViewAfterTextChangeEvent) throws Throwable {

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "过滤之后-监听到的内容是->" + textViewAfterTextChangeEvent.getView().getText().toString());

                        String inputValue = textViewAfterTextChangeEvent.getView().getText().toString();

                        if (!TextUtils.isEmpty(inputValue)) {

                            int length = inputValue.length();

                            if (length < ConstantApi.IS_PHONE_NUMBER_LENGTH) {

                                //如果小于11位，那么控制搜索按钮不可用？,那就说明还没有结果，要隐藏提示语句
                                CommUtils.setViewGone(textViewCardForbidden);

                            } else if (length == ConstantApi.IS_PHONE_NUMBER_LENGTH) {

//                                determinate_circular_small_progress.setVisibility(View.VISIBLE);
//                                KeyboardUtils.hideSoftInput(CardMainPushActivity.this);

                                method_SearchSomeThing(false);

                            }


//                            else {
//                                determinate_circular_small_progress.setVisibility(View.GONE);
//                            }

                        }

//                        if (et_searchInCustom.isFocused()) {
//                                //LogUtils.d(ConstantApi.LOGCAT_NOMAL + "afterTextChangeEvents--处于获取焦点状态");
//                                et_searchInCustom.clearFocus();//如果处于占用焦点之中，那么清理焦点
//                            }

//                        if (TextUtils.isEmpty(textViewAfterTextChangeEvent.getView().getText().toString())) {
//                            if (textViewInputPhoneChoose != null) {
//                                textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
//                            }
//                        }

                    }
                }, new Consumer<Throwable>() {

                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                    }
                });

    }

    //默认选中【优惠券】有一些条件的重置，
    private void method_refresh_reset() {

        care_cardOrPackage_type = CardCareTypes.TYPE_COUPONS.getIndex();

        // TODO: 2023-10-07 15:29 如果类型值被填充，清空上次选中的【优惠券类型】
        couponId_upLoad = "";


        if (radiaoButtonChooseTypeCoupons != null) {
            radiaoButtonChooseTypeCoupons.setChecked(true);
        }

        if (radiaoButtonChooseTypeGreatPackage != null) {
            radiaoButtonChooseTypeGreatPackage.setChecked(false);
        }

        //默认文字：类型 是卡券类型
        if (textViewCardTypeDes != null) {
            textViewCardTypeDes.setText(getString(R.string.choose_card_type_coupon));
        }

        //默认 选中 卡券的或者是礼包 填充的类型
        if (textViewEditViewCardTypeName != null) {
            textViewEditViewCardTypeName.setText("");
            textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_card_form));
        }

        //清空手机号信息
        if (editViewInputCustomerPhoneSearch != null) {
            editViewInputCustomerPhoneSearch.setText("");
        }


    }

    @Override
    protected void gainDatas() {

        //是否有其他需要调用接口的地方；
        if (NetworkUtils.isConnected()) {

            //同时间获取卡券类型的列表
            getServerDatasCouponType(null);

            //这个次要，如果没有直接不展示也可以，但是卡券类型必须先获取为了提交数据；
//            getServerDatasCardHistory();

        } else {
            //是否有其他的执行逻辑？
            //netWorkError();
            // : 2023-08-14 15:22 添加页面遮盖，使用adapter自有的方式来填充
        }

    }


    //搜索客户的信息内容
    private void gainCustomerByPhone(String _userPhone, boolean isShowLoadDialog) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.phone, _userPhone);//,
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
        //map.put(Parameterkey.isCarNo, CouponIsCarNoType.ISCARNUMBER_NO.getIndex());//是否限制车牌使用：0代表否；1代表 是；限制车牌查询店铺会员，不限制查询平台会员；
        map.put(Parameterkey.isCarNo, isCarNo_upLoad);//是否限制车牌使用：0代表否；1代表 是；限制车牌查询店铺会员，不限制查询平台会员；
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.GETSHOPLATENTCUSTOMERLIST_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getShopLatentCustomerList_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCustomerByPhone(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<CustomerPerson>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);
                        CommUtils.setViewVisible(textViewCardForbidden);
                        CommUtils.myCustomMessageShow(mActivityInstance, textViewCardForbidden, serverMessage);


                        //无数据的需要转换提示
                        //{"data":"","message":"无数据","code":"20002"}


                        //勿删除：
                        //这里仅仅给提示即可
//                        if (!TextUtils.isEmpty(serverMessage)) {
////                            ToastUtils.showShort(serverMessage);
//                            PopTip.show(serverMessage).iconWarning();
//                        } else {
//                            PopTip.show(getString(R.string.not_search_customer)).iconWarning();
//                        }

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        CommUtils.setViewGone(textViewCardForbidden);

                        if (isShowLoadDialog) {
                            //如果是自动搜索的，就不弹加载进度圈
                            //如果是点击【搜索】，就弹窗
                            method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_LOADING);

                        }

                    }
                }).subscribe(new Consumer<ArrayList<CustomerPerson>>() {
                    @Override
                    public void accept(ArrayList<CustomerPerson> customerPersonArrayList) throws Throwable {

                        //如果搜索出来有数据，就隐藏软键盘
                        KeyboardUtils.hideSoftInput(CardMainPushActivity.this);

                        CommUtils.setViewGone(textViewCardForbidden);

                        //搜索完毕，即关闭进度圈
                        CommUtils.checkMaterialDialog(materialDialog);

                        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
                            mDataResources_customerPerson_for_popu.clear();
                        }

                        if (mDataResources_customerPerson_outSide != null && !mDataResources_customerPerson_outSide.isEmpty()) {
                            mDataResources_customerPerson_outSide.clear();
                        }

                        if (customerPersonArrayList != null && !customerPersonArrayList.isEmpty()) {

                            for (CustomerPerson customerPerson : customerPersonArrayList) {

                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                //
                                evaluateWadeInfo.setDictCode(customerPerson.getCustomerId());
                                evaluateWadeInfo.setDictLabel(customerPerson.getTrueName());
                                //这个特殊，需要展示手机号信息
                                evaluateWadeInfo.setUserPhoneNumber(customerPerson.getPhone());
                                //这个也是特殊展示，展示车牌号的
                                evaluateWadeInfo.setCarNumber(customerPerson.getCarNo());

                                //默认都是false
                                evaluateWadeInfo.setChecked(false);

                                if (mDataResources_customerPerson_for_popu != null) {
                                    mDataResources_customerPerson_for_popu.add(evaluateWadeInfo);
                                }

                                if (mDataResources_customerPerson_outSide != null) {
                                    mDataResources_customerPerson_outSide.add(customerPerson);
                                }

                            }

                            //-----------------------------------------------------------------------------------------------------------
                            //如果数据仅仅是只有一条，那么默认直接选中，减少一步用户操作：
                            if (mDataResources_customerPerson_for_popu != null && mDataResources_customerPerson_for_popu.size() == 1) {
                                mDataResources_customerPerson_for_popu.get(0).setChecked(true);
                            }
                            //-----------------------------------------------------------------------------------------------------------


                        } else {
                            //直接提示 搜索信息为空
                            PopTip.show(getString(R.string.not_search_customer)).iconWarning();
                        }

                        //-----------------------------------------------------------------------------------------------------------
                        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {

                            //这里需要判断
                            if (isCarNo_upLoad == 0) {
                                method_showCustomerPersonDialog();
                            } else if (isCarNo_upLoad == 1) {
                                method_showCustomerPersonDialog_twoList();
                            }

                        }
                        //-----------------------------------------------------------------------------------------------------------

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        //页面报错；
                        CommUtils.checkMaterialDialog(materialDialog);
                        CommUtils.setViewGone(textViewCardForbidden);

                    }
                });

    }

    //通用的搜索逻辑,以手机号为搜索条件
    private void method_SearchSomeThing(boolean isShowLoadDialog) {

        String inputPhoneNumber = editViewInputCustomerPhoneSearch.getText().toString().trim();

        //手机号没有填写，是不能通过的
        if (TextUtils.isEmpty(inputPhoneNumber)) {//必须填充手机号的
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_upload), true);
            mAlertView.show();
            return;
        }

        //校验用户输入的手机号
        if (!RegexUtils.isMobileSimple(inputPhoneNumber)) {
            //CommUtils.displayToastShort(LoginActivity.this, "电话格式不对");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_format), true);
            mAlertView.show();
            return;
        }

        if (!RegexUtils.isMobileExact(inputPhoneNumber)) {//精确验证手机号
            //CommUtils.displayToastShort(LoginActivity.this, "请输入有效手机号");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_effective), true);
            mAlertView.show();
            return;
        }

        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
            mDataResources_customerPerson_for_popu.clear();
        }


        gainCustomerByPhone(editViewInputCustomerPhoneSearch.getText().toString().trim(), isShowLoadDialog);


    }

    //添加：弹出搜索出来的客户的列表，一般地是仅仅只有一条数据的；
    private void method_showCustomerPersonDialog() {

        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardMainPushActivity.this,//
                ExtraValue.MODIFY_EVALUATE_CARMAIN_PERSON_SELECT,//
                mDataResources_customerPerson_for_popu);

        evaluateWadePopu.setTitleName(getResources().getString(R.string.dialog_des_title));

        //搜索要弹窗的：客户信息
        basePopupView_customerPerson = new XPopup.Builder(CardMainPushActivity.this)
                .hasShadowBg(true)
                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面;
                .isViewMode(true)
                //.autoDismiss(false)
                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                //.dismissOnTouchOutside(true)
                //.notDismissWhenTouchInView()
                .asCustom(evaluateWadePopu)//
                .show();

    }

    //填充车牌和人员列表的多列表信息
    private void method_showCustomerPersonDialog_twoList() {

        CardTwoListPopu cardTwoListPopu = new CardTwoListPopu(CardMainPushActivity.this,//
                ExtraValue.MODIFY_EVALUATE_CARMAIN_PERSON_SELECT,//
                mDataResources_customerPerson_for_popu);

        cardTwoListPopu.setTitleName(getResources().getString(R.string.dialog_des_title));

        //搜索要弹窗的：客户信息
        basePopupView_cardTwoListPopu = new XPopup.Builder(CardMainPushActivity.this)
                .hasShadowBg(true)
                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面;
                .isViewMode(true)
                //.autoDismiss(false)
                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                //.dismissOnTouchOutside(true)
                //.notDismissWhenTouchInView()
                .asCustom(cardTwoListPopu)//
                .show();

    }

    //获取优惠券的类型；页面打开默认直接调取的；
    private void getServerDatasCouponType(GainDataCallBackListener _gainDataCallBackListener) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETCOUPONBYSHOPINFO_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getCouponByShopInfo_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCouponByShopInfo(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<CouponCustomer>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        //2024-1-3 10:51:00 bug:刷新优惠券弹窗列表的同时要清空

                        if (mDataResources_couponCustomer != null && !mDataResources_couponCustomer.isEmpty()) {
                            mDataResources_couponCustomer.clear();
                        }

                        if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {
                            mDataResources_cardTypeOrPackageType_popu.clear();
                        }

                    }
                }).subscribe(new Consumer<ArrayList<CouponCustomer>>() {
                    @Override
                    public void accept(ArrayList<CouponCustomer> couponCustomers) throws Throwable {

                        if (couponCustomers != null && !couponCustomers.isEmpty()) {

                            for (CouponCustomer couponCustomerItem : couponCustomers) {

                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                evaluateWadeInfo.setDictCode(couponCustomerItem.getCouponId());//优惠券的id
                                evaluateWadeInfo.setDictLabel(couponCustomerItem.getCouponName());//优惠券的名称

                                if (mDataResources_cardTypeOrPackageType_popu != null) {
                                    mDataResources_cardTypeOrPackageType_popu.add(evaluateWadeInfo);
                                }

                                if (mDataResources_couponCustomer != null) {
                                    mDataResources_couponCustomer.add(couponCustomerItem);
                                }

                            }
                        }

                        //额外的执行
                        if (_gainDataCallBackListener != null) {
                            _gainDataCallBackListener.doSomeThing();
                        }

                    }
                }, new ErrorConsumer() {
                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                        function_apiException(apiException);
                    }
                });
    }

    //获取 礼包的类型；可以直接获取，也可以当选中【优惠礼包】时候再次获取
    private void getServerDatasGreatPackageType(GainDataCallBackListener _gainDataCallBackListener) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETCOUPONPACKLISTBYSHOP_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getCouponPackListByShop_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setAlertToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCouponPackListByShop(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<GreatPackageCustomerVo>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        //没有优惠礼包给醒目提示
//                        ApiException--code=>20002--message=>无数据
                        function_response_20002(serverCode, serverMessage, addLogUpLoadInfo, false);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "优惠礼包执行到 是否清空数据操作");

                        if (mDataResources_greatPackageCustomer != null && !mDataResources_greatPackageCustomer.isEmpty()) {
                            mDataResources_greatPackageCustomer.clear();
                        }

                        if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {
                            mDataResources_cardTypeOrPackageType_popu.clear();
                        }

                    }
                }).subscribe(new Consumer<ArrayList<GreatPackageCustomerVo>>() {
                    @Override
                    public void accept(ArrayList<GreatPackageCustomerVo> greatPackageCustomers) throws Throwable {

                        //无数据的时候 是否走到执行成功逻辑。
//                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "执行到 是否清空数据操作");

                        if (greatPackageCustomers != null && !greatPackageCustomers.isEmpty()) {

                            for (GreatPackageCustomerVo greatPackageCustomerVoItem : greatPackageCustomers) {

                                // TODO: 2023-10-07 15:50 纠错
                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                evaluateWadeInfo.setDictCode(greatPackageCustomerVoItem.getCouponPackId());//优惠券的id
                                evaluateWadeInfo.setDictLabel(greatPackageCustomerVoItem.getCouponName());//优惠券的名称

                                if (mDataResources_cardTypeOrPackageType_popu != null) {
                                    mDataResources_cardTypeOrPackageType_popu.add(evaluateWadeInfo);
                                }

                                //选中 做上传 是 优惠礼包类型的；
                                if (mDataResources_greatPackageCustomer != null) {
                                    mDataResources_greatPackageCustomer.add(greatPackageCustomerVoItem);
                                }

                            }

                        }

                        //额外的执行
                        if (_gainDataCallBackListener != null) {
                            _gainDataCallBackListener.doSomeThing();
                        }

                    }
                }, new ErrorConsumer() {
                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                        function_apiException(apiException);
                    }
                });
    }

    //发送礼包的接口
    private void method_gainAddSubmitInfo_upLoad_for_greatPackage() {

        String explainText = editViewContentReasonCou.getText().toString().trim();

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.customerId, customerId_upLoad);//
        map.put(Parameterkey.couponPackId, couponPackId_upLoad);//此礼包的 id
        map.put(Parameterkey.carNo, carNo_upLoad);//
        map.put(Parameterkey.explain, explainText);//发送优惠券礼包的原因

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SENDCOUPONTOCUSTOMER_GREAT_PACKAGE_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.sendCouponToCustomer_great_package_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .sendCouponToCustomer_great_package(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                        CommUtils.checkMaterialDialog(materialDialog);
                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);
                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        //这里提交成功之后，删除文本框之中的手机号信息
                        if (editViewInputCustomerPhoneSearch != null) {

//                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "editViewInputCustomerPhoneSearch-重置为空");
                            editViewInputCustomerPhoneSearch.post(new Runnable() {
                                @Override
                                public void run() {

                                    editViewInputCustomerPhoneSearch.setText("");

//                                    if (textViewInputPhoneChoose != null) {
//                                        textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
//                                    }

                                }
                            });

                        }

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);

                        methodSubmitSuccess(CardMainPushActivity.this, new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                //重新刷新 历史记录列表，因为有新数据 新增了；
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "即将执行 刷新 发放的历史记录 接口");

                                //: 2024/1/10 16:57 发送礼包完毕，通知首页的发放历史记录刷新。
//                                EventCardMain eventCardMain = new EventCardMain();
//                                eventCardMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST);
//                                EventBus.getDefault().post(eventCardMain);

                                methodBack();

                            }
                        });

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        //
//                        if (apiException != null) {
//                            if (!TextUtils.isEmpty(apiException.getDisplayMessage())) {
//                                ToastUtils.showShort(apiException.getDisplayMessage());
//                            }
//                        }

                        function_apiException(apiException);

                    }
                });

    }

    //执行上传发送这个优惠券的操作,发放卡券的接口
    private void method_gainAddSubmitInfo_upLoad_for_couponCard() {

        //发送优惠券的原因
        String explainText = editViewContentReasonCou.getText().toString().trim();

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.customerId, customerId_upLoad);//
        map.put(Parameterkey.couponId, couponId_upLoad);//
        map.put(Parameterkey.carNo, carNo_upLoad);
        map.put(Parameterkey.explain, explainText);//发送优惠券原因

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SENDCOUPONTOCUSTOMER_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.sendCouponToCustomer_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .sendCouponToCustomer(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                        CommUtils.checkMaterialDialog(materialDialog);
                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {
                        method_create_materialDialog(mActivityInstance, ConstantSign.TIPS_SUBMIT);
                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        //这里提交成功之后，删除文本框之中的手机号信息
                        if (editViewInputCustomerPhoneSearch != null) {

//                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "editViewInputCustomerPhoneSearch-重置为空");
                            editViewInputCustomerPhoneSearch.post(new Runnable() {
                                @Override
                                public void run() {

                                    editViewInputCustomerPhoneSearch.setText("");
//                                    if (textViewInputPhoneChoose != null) {
//                                        textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
//                                    }

                                }
                            });

                        }

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);

                        methodSubmitSuccess(CardMainPushActivity.this, new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                //重新刷新 历史记录列表，因为有新数据 新增了；
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "即将执行 刷新 发放的历史记录 接口");

                                //: 2024/1/10 16:57 发送礼包完毕，通知首页的发放历史记录刷新。
                                EventCardMain eventCardMain = new EventCardMain();
                                eventCardMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST);
                                EventBus.getDefault().post(eventCardMain);

                                methodBack();

                            }
                        });

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        function_apiException(apiException);

                    }
                });

    }

    //优惠券的发放历史的审核状态；
    private void method_gainVerifySubmitInfo_upLoad(Integer _couponCustomerId, String _couponId, Integer _auditStatus) {

//        {
//                "couponCustomerId": 62986, //发放的优惠券记录主键Id
//                "couponId": 1, //优惠券主键Id
//                "auditStatus": 1 //审核状态 0：待审核 1：审核通过 2：审核不通过
//        }

//        CardAuditStatus {
//            //审核状态 0：待审核 1：审核通过 2：审核不通过
//                    STATUS_NOT_VERIFY("0", "待审核"),
//                    STATUS_HAS_VERIFY("1", "审核通过"),
//                    STATUS_CANNOT_VERIFY("2", "审核不通过");

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.couponCustomerId, _couponCustomerId);//
        map.put(Parameterkey.couponId, _couponId);
        map.put(Parameterkey.auditStatus, CardAuditStatus.STATUS_HAS_VERIFY.getIndex());

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_UPDATEAUDITSTATUS_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.updateAuditStatus_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .updateAuditStatus(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        if (!TextUtils.isEmpty(serverMessage)) {
                            PopTip.show(serverMessage).iconWarning();
                        }

                    }
                })).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);

                        methodSubmitSuccess(CardMainPushActivity.this, new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                // TODO: 2024/1/10 16:58 通知外侧发放历史记录首页列表刷新

                                //通知主页列表刷新
//                                pagination_upLoad = Parameterkey.pageNum_default_first;
//
//                                if (mDataResources != null && !mDataResources.isEmpty()) {
//                                    mDataResources.clear();
//                                }
//
//                                if (cardMainBottomAdapter != null) {
//                                    cardMainBottomAdapter.notifyDataSetChanged();
//                                }
//
//                                getServerDatasCardHistory();

                            }
                        });


                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                    }
                });
    }

//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void onEventMainThreadInCardMain(EventCardMain eventCardMain) {
//
//        if (eventCardMain != null) {
//
//            if (eventCardMain.getMessage() == ExtraValue.EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST) {
//
//                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "收到刷新主页列表的消息--EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST");
//
//                //如果发起搜索，要重置 第1页
//                pagination_upLoad = Parameterkey.pageNum_default_first;
//
//                //清空历史数据
//                if (mDataResources != null && !mDataResources.isEmpty()) {
//                    mDataResources.clear();
//                }
//
//                if (cardMainBottomAdapter != null) {
//                    cardMainBottomAdapter.notifyDataSetChanged();
//                }
//
//                getServerDatasCardHistory();
//
//            }
//
//        }
//
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

//        if (mDataResources != null && !mDataResources.isEmpty()) {
//            mDataResources.clear();
//        }
//
//        if (cardMainBottomAdapter != null) {
//            cardMainBottomAdapter.notifyDataSetChanged();
//            cardMainBottomAdapter = null;
//        }

        if (basePopupViewCardTypeOrgreatPackage != null) {
            basePopupViewCardTypeOrgreatPackage.onDestroy();
            basePopupViewCardTypeOrgreatPackage = null;
        }

        if (basePopupView_customerPerson != null) {
            basePopupView_customerPerson.onDestroy();
            basePopupView_customerPerson = null;
        }

        if (basePopupView_cardTwoListPopu != null) {
            basePopupView_cardTwoListPopu.onDestroy();
            basePopupView_cardTwoListPopu = null;
        }

        EventBus.getDefault().unregister(this);

    }

    @Override
    protected void methodBack() {
        if (ActivityUtils.isActivityAlive(this)) {
            ActivityUtils.finishActivity(this);
        }

    }
}